package org.example.springboot3.controller;

import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.example.springboot3.common.Result;
import org.example.springboot3.entity.Blog;
import org.example.springboot3.service.BlogService;
import org.springframework.web.bind.annotation.*;
import java.util.List;


@RestController
@RequestMapping("/blogmanage")
public class BlogController {

    @Resource
    private BlogService blogService;

    /**
     * 查询所有的数据
     */
    @GetMapping("/selectAll")
    public Result selectAll(Blog blog){
        List<Blog> list = blogService.selectAll(blog);
        return Result.success(list);
    }
    /**
     * 分页查询的数据
     * pageNum: 当前页码
     * pageSize: 每页的个数
     */
    @GetMapping("/selectPage")
    public Result selectPage(Blog blog,
       @RequestParam (defaultValue = "1") Integer pageNum,
       @RequestParam(defaultValue = "10") Integer pageSize) {
            PageInfo<Blog> pageInfo = blogService.selectPage(blog,pageNum,pageSize);
            return Result.success(pageInfo);
    }

    /**
     * 查询单个数据
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Blog blog = blogService.selectById(id);
        return Result.success(blog);
    }

    /**
     * 新增数据
     */
    @PostMapping("/add")
    public Result add(@RequestBody Blog blog) {
        blogService.add(blog);
        return Result.success();
    }
    /**
     * 删除单个数据
     */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        blogService.deleteById(id);
        return Result.success();
    }
    /**
     * 批量删除数据
     */
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        blogService.deleteBatch(ids);
        return Result.success();
    }
    /**
     * 更新数据
     */
    @PutMapping("/update")
    public Result update(@RequestBody Blog blog) {
        blogService.update(blog);
        return Result.success();
    }

}//

    









